package com.letv.android.client.episode.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.letv.android.young.client.R;
import com.letv.android.client.episode.callback.PinnedHeaderExpListViewCallBack;
import com.letv.android.client.episode.utils.EpisodeUtils;
import com.letv.android.client.episode.widget.ExpandableHeightGridViewPlayerLibs;
import com.letv.android.client.utils.UIs;
import com.letv.android.client.widget.LetvImageView;
import com.letv.core.bean.AlbumNew;
import com.letv.core.bean.VideoBean;
import com.letv.core.bean.VideoListBean;
import com.letv.core.download.image.ImageDownloader;
import com.letv.core.utils.LogInfo;

import java.util.HashMap;

public class DetailHalfPlayExpandableListAdapterPlayerLibs extends BaseExpandableListAdapter implements PinnedHeaderExpListViewCallBack {
    private Context mContext;
    private ViewHolderGroup viewHolderGroup;
    private LayoutInflater layoutInflater = null;
    private int total;
	private String episodes;//运营商填写的视频总集数（只用于UI显示）
    private long curVid;
    private int curPage;
    private int pageSize;
    private VideoBean currVideoPlayerLibs;
    private long aid;
    public HashMap<Integer, VideoListBean> videosMap;
//    public HashMap<Long, DownloadVideo> downloadVideoHashMap;
    private AdapterView.OnItemClickListener onItemClickListener;
    private boolean isList = false;
    private int mPinnedHeaderBackgroundColor;
    private int mPinnedHeaderTextColor;
    private int loadGroupPosition;			//正在加载组位置
    private boolean loadProgressingFlag;	//当前正在加载组是否处于正在加载状态
    private int mCurGridItemHeight = 0;
    private boolean isDownload;
    private SparseArray<int[]> groupRangceMap = new SparseArray<int[]>(); //每个group中的集数范围 eg： 1 - 100集

    /*
     * Child View view holder
     */
    private ViewChildHolderGridView mViewHolder = null;    
    
    private VideoListBean mCurVideoList;
    /**
     * 锁
     * */
    private boolean lock;
    
    private int mNumColumns = 5;
    private boolean isLandscape = false;

    public final class ViewHolderGroup {
        public TextView titleView;
        public ImageView arrowView;
        public ProgressBar progressBarView;
    }

    public DetailHalfPlayExpandableListAdapterPlayerLibs(Context context, int total, int curPage, int pageSize, long curVid,
                                                         VideoBean currVideoPlayerLibs, HashMap<Integer, VideoListBean> videosMap) {
        mContext = context;
        this.total = total;
        this.curPage = curPage;
        this.pageSize = pageSize;
        this.curVid = curVid;
        this.videosMap = videosMap;
        this.currVideoPlayerLibs = currVideoPlayerLibs;
        layoutInflater = LayoutInflater.from(context);
        mPinnedHeaderBackgroundColor = mContext.getResources().getColor(R.color.letv_color_ffdfdfdf);
        mPinnedHeaderTextColor = mContext.getResources().getColor(R.color.letv_color_ff969696);
    }

    public void setList(int curPage, HashMap<Integer, VideoListBean> videosMap) {
        this.curPage = curPage;
        this.videosMap = videosMap;        
    }
    
    public int getTotal() {
		return total;
	}

	public SparseArray<int[]> getGroupRangceMap() {
        return groupRangceMap;
    }

    public void setIsDownload(boolean isDownload) {
        this.isDownload = isDownload;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        if(!isList) {
            if (videosMap != null) {
                VideoListBean mVideoList = videosMap.get(groupPosition + 1);
                if (mVideoList != null) {
                    return mVideoList;
                }
            }
        } else {
            if (videosMap != null) {
                VideoListBean mVideoList = videosMap.get(groupPosition + 1);
                if (mVideoList != null && mVideoList.size() > childPosition) {
                    return mVideoList.get(childPosition);
                }
            }
        }
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }
    
    public void setProgressingParam(int groupPosition, boolean progressingFlag) {
    	loadGroupPosition = groupPosition;
    	loadProgressingFlag = progressingFlag;
    }
    

	public void setEpisodes(String episodes) {
		this.episodes = episodes;
	}
	
	//add by yangn
	AlbumNew mAlbumNewPlayerLibs=null;
	public void setAlbumNewPlayerLibs(AlbumNew album){
		mAlbumNewPlayerLibs=album;
	}
		//add  by yangn end

	/**
     * 创建宫格
     */
    private void createVideosGrid(final long curId,final VideoListBean list, final ViewChildHolderGridView mViewHolder) {
        mViewHolder.expandChildGridView.setNumColumns(mNumColumns);
        mViewHolder.expandChildGridViewAdapter.setList(list);
        mViewHolder.expandChildGridViewAdapter.setCurId(curId);
        mViewHolder.expandChildGridViewAdapter.notifyDataSetChanged();

        if (list != null && list.size() > 0 && currVideoPlayerLibs != null) {
            int videoIndex = list.indexOf(currVideoPlayerLibs);
            if (videoIndex != -1) {
                mViewHolder.expandChildGridView.setSelection(videoIndex);
            }
        }
    }

    /**
     * 创建列表
     */
    private void createVideosList(long curId, ViewChildHolderListView mViewHolder, VideoBean mVideo, View convertView){
        switch (mVideo.getCid()){
            case AlbumNew.Channel.TYPE_H265:
            case AlbumNew.Channel.TYPE_MOVIE:
            case AlbumNew.Channel.TYPE_DOLBY:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setText(mVideo.getNameCn());
                if(!TextUtils.isEmpty(mVideo.getSubTitle())){
                    mViewHolder.subTitleView.setVisibility(View.VISIBLE);
                    mViewHolder.subTitleView.setText(mVideo.getSubTitle());
                    mViewHolder.subTitleView.setSingleLine();
                    mViewHolder.titleView.setSingleLine();
                } else {
                    mViewHolder.subTitleView.setVisibility(View.GONE);
                    mViewHolder.titleView.setMaxLines(2);
                }
                if(!TextUtils.isEmpty(mVideo.getDuration()+"")) {
                    mViewHolder.videoTime.setVisibility(View.VISIBLE);
                    mViewHolder.videoTime.setText(EpisodeUtils.stringForTimeNoHour(mVideo.getDuration() * 1000));
                } else {
                    mViewHolder.videoTime.setVisibility(View.GONE);
                }
                mViewHolder.videoScore.setVisibility(View.VISIBLE);
                mViewHolder.videoScore.setText("8.9分");
                //缺少播放数
                break;
            case AlbumNew.Channel.TYPE_TVSHOW:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                if(!TextUtils.isEmpty(mVideo.getSubTitle())) {
                    mViewHolder.titleView.setText(mVideo.getSubTitle());
                } else {
                    mViewHolder.titleView.setText(mVideo.getNameCn());
                }
                if(!TextUtils.isEmpty(mVideo.getGuest())){
                    mViewHolder.subTitleView.setVisibility(View.VISIBLE);
                    mViewHolder.subTitleView.setText(mVideo.getGuest());
                    mViewHolder.subTitleView.setMaxLines(1);
                    mViewHolder.titleView.setMaxLines(1);
                } else {
                    mViewHolder.subTitleView.setVisibility(View.GONE);
                    mViewHolder.titleView.setMaxLines(2);
                }
                mViewHolder.videoTime.setVisibility(View.VISIBLE);
                mViewHolder.videoTime.setText(mVideo.getEpisode());
                break;
            case AlbumNew.Channel.TYPE_MUSIC:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setText(mVideo.getNameCn());
                if(!TextUtils.isEmpty(mVideo.getSinger())){
                    mViewHolder.subTitleView.setVisibility(View.VISIBLE);
                    mViewHolder.subTitleView.setText(mVideo.getSinger());
                    mViewHolder.subTitleView.setMaxLines(1);
                    mViewHolder.titleView.setMaxLines(1);
                } else {
                    mViewHolder.subTitleView.setVisibility(View.GONE);
                    mViewHolder.titleView.setMaxLines(2);
                }
                mViewHolder.videoTime.setVisibility(View.VISIBLE);
                mViewHolder.videoTime.setText(EpisodeUtils.stringForTimeNoHour(mVideo.getDuration()* 1000));
                break;
            case AlbumNew.Channel.TYPE_DOCUMENT_FILM:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setMaxLines(2);
                if(!TextUtils.isEmpty(mVideo.getNameCn())) {
                    mViewHolder.titleView.setText(mVideo.getNameCn());
                } else {
                    mViewHolder.titleView.setText(mVideo.getSubTitle());
                }
                mViewHolder.videoTime.setVisibility(View.VISIBLE);
                mViewHolder.videoTime.setText(mVideo.getEpisode());
                break;
            //体育/热点/NBA/财经/汽车/旅游
            //缺少财经---------
            case AlbumNew.Channel.TYPE_PE:
            case AlbumNew.Channel.TYPE_NBA:
            case AlbumNew.Channel.TYPE_FINANCIAL:
            case AlbumNew.Channel.TYPE_CAR:
            case AlbumNew.Channel.TYPE_TOURISM:
            case AlbumNew.Channel.TYPE_FASHION:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setMaxLines(2);
                if(!TextUtils.isEmpty(mVideo.getNameCn())) {
                    mViewHolder.titleView.setText(mVideo.getNameCn());
                } else {
                    mViewHolder.titleView.setText(mVideo.getSubTitle());
                }
                break;
            case AlbumNew.Channel.TYPE_JOY:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setMaxLines(2);
                if(!TextUtils.isEmpty(mVideo.getNameCn())) {
                    mViewHolder.titleView.setText(mVideo.getNameCn());
                } else {
                    mViewHolder.titleView.setText(mVideo.getSubTitle());
                }
                mViewHolder.videoTime.setVisibility(View.VISIBLE);
                mViewHolder.videoTime.setText(mVideo.getEpisode());
                break;
            default:
                mViewHolder.titleView.setVisibility(View.VISIBLE);
                mViewHolder.titleView.setMaxLines(2);
                if(!TextUtils.isEmpty(mVideo.getNameCn())) {
                    mViewHolder.titleView.setText(mVideo.getNameCn());
                } else {
                    mViewHolder.titleView.setText(mVideo.getSubTitle());
                }
                mViewHolder.videoTime.setVisibility(View.VISIBLE);
                mViewHolder.videoTime.setText(EpisodeUtils.stringForTimeNoHour(mVideo.getDuration()* 1000));
                break;
        }
        if (mVideo.getPlayCount() > 0) {
	        mViewHolder.playNumView.setVisibility(View.VISIBLE);
	        mViewHolder.playNumView.setText(EpisodeUtils.getPlayCountsToStr(mVideo.getPlayCount()));
        }
        else {
        	mViewHolder.playNumView.setVisibility(View.GONE);
        }
        String strImageUrl = getImageUrl(mVideo);
        if (!TextUtils.isEmpty(strImageUrl)) {
        	mViewHolder.videoImageView.setImageResource(R.drawable.letv_poster_defualt_pic);
        	ImageDownloader.getInstance(mContext).download(mViewHolder.videoImageView, strImageUrl);
        }
        else {
        	mViewHolder.videoImageView.setImageResource(R.drawable.letv_poster_defualt_pic);
        }
        
        int dbBeanFinish = -1;
//        if (mVideo.canDownload() && downloadVideoHashMap.size() > 0 ) {
//            if (downloadVideoHashMap.containsKey(mVideo.getId())) {
//                dbBeanFinish = downloadVideoHashMap.get(mVideo.getId()).state;
//            }
//        }
        if (dbBeanFinish >= 0) {
            if (dbBeanFinish == 4) {// 完成
                mViewHolder.localTextView.setVisibility(View.VISIBLE);
                mViewHolder.localTextView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff07c708));
//                mViewHolder.localTextView.setText(R.string.download_finish_local);
            } else if (dbBeanFinish == 0 || dbBeanFinish == 1) {// 进行中
                mViewHolder.localTextView.setVisibility(View.GONE);
                mViewHolder.localTextView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff5c5c5c));
            } else {
                mViewHolder.localTextView.setVisibility(View.GONE);
                mViewHolder.localTextView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff5c5c5c));
            }
        } else {
            convertView.setBackgroundResource(R.color.letv_color_00ffffff);
        }
        if (curId == mVideo.getId()) {
            mViewHolder.titleView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ffffffff));
            mViewHolder.subTitleView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ffffffff));
            mViewHolder.playNumView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ffffffff));
            mViewHolder.videoScore.setTextColor(mContext.getResources().getColor(R.color.letv_color_ffff0000));
            mViewHolder.playNumView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.letv_playnum_select, 0,0,0);
            convertView.setBackgroundResource(R.color.letv_color_ff00a0e9);
        } else {
            mViewHolder.titleView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff5c5c5c));
            mViewHolder.subTitleView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff5c5c5c));
            mViewHolder.playNumView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.letv_playnum_normal, 0, 0, 0);
            mViewHolder.playNumView.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff5c5c5c));
            mViewHolder.videoScore.setTextColor(mContext.getResources().getColor(R.color.letv_color_ff08c809));
            convertView.setBackgroundResource(R.drawable.letv_half_play_relate_item_selecter);
//            convertView.setBackgroundResource(R.color.letv_color_ffffffff);
        }
    }
    /**
     * block图片地址获取
     * @param mVideo
     * @return
     */
    private String getImageUrl(VideoBean mVideo) {
    	String strRetUrl = "";
    	if (mVideo != null) {
    		if (!TextUtils.isEmpty(mVideo.getPic320())) {
    			strRetUrl = mVideo.getPic320();
    		}
    		else if (!TextUtils.isEmpty(mVideo.getPic300())) {
    			strRetUrl =  mVideo.getPic300();
    		}
    		else if (!TextUtils.isEmpty(mVideo.getPic())) {
    			strRetUrl =  mVideo.getPic();
    		}    		
    	}
    	return strRetUrl;
    }
    
//    public int getGridItemHeight() {
//    	if (mCurGridItemHeight == 0) {
//    		mCurGridItemHeight = Math.min(UIsUtils.getScreenHeight(), UIsUtils.getScreenWidth()) * 11 / 80; // width / 5) * 11 / 16
//    	}
//    	return mCurGridItemHeight;
//    }
    
    public void setNumColumn(int numColumns) {
        mNumColumns = numColumns;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
                             ViewGroup parent) {
        if(!isList) {
            mCurVideoList = (VideoListBean) getChild(groupPosition, childPosition);             
            if (convertView == null) {
                mViewHolder = new ViewChildHolderGridView();
                convertView = layoutInflater.inflate(R.layout.letv_detail_half_expand_child_gridview_selecter_playerlibs, parent, false);
                mViewHolder.expandChildGridView = (ExpandableHeightGridViewPlayerLibs) convertView.findViewById(R.id.detailplay_half_video_expand_child_gridview);
                mViewHolder.top = convertView.findViewById(R.id.top);
                mViewHolder.bottom = convertView.findViewById(R.id.bottom);
                mViewHolder.top.setVisibility(View.GONE);
                mViewHolder.bottom.setVisibility(View.GONE);
                mViewHolder.expandChildGridView.setNumColumns(mNumColumns);
                mViewHolder.expandChildGridViewAdapter = new DetailVideosGridAdapterPlayerLibs(mContext);
                mViewHolder.expandChildGridViewAdapter.setList(mCurVideoList);
                mViewHolder.expandChildGridViewAdapter.setDownload(isDownload);
                mViewHolder.expandChildGridViewAdapter.setCurId(curVid);
                mViewHolder.expandChildGridViewAdapter.setIsLandscape(isLandscape);
                mViewHolder.expandChildGridView.setAdapter(mViewHolder.expandChildGridViewAdapter);
                mViewHolder.expandChildGridView.setOnItemClickListener(onItemClickListener);
                mViewHolder.expandChildGridView.setOnScrollListener(onGirdViewScrollListener);
                convertView.setTag(mViewHolder);
            } else {
                mViewHolder = (ViewChildHolderGridView) convertView.getTag();
                int padding = UIs.dipToPx(mContext, 10);
                mViewHolder.expandChildGridView.setPadding(padding, 0, padding, 0);
                createVideosGrid(curVid, mCurVideoList, mViewHolder);
            }

//            if (mViewHolder.expandChildGridViewAdapter.downloadVideoHashMap == null) {
//                mViewHolder.expandChildGridViewAdapter.downloadVideoHashMap = downloadVideoHashMap;
//            }
        } else {
            VideoBean mVideo = (VideoBean) getChild(groupPosition, childPosition);
            if(mVideo == null ){
                return null;
            }
            ViewChildHolderListView mViewHolder = null;
            if (convertView == null) {
                mViewHolder = new ViewChildHolderListView();
                convertView = layoutInflater.inflate(R.layout.letv_detailplay_half_list_item_playerlibs, null);
                mViewHolder.localTextView = (TextView)convertView.findViewById(R.id.videos_list_item_download_state_txt);
                mViewHolder.titleView = (TextView)convertView.findViewById(R.id.videos_list_item_title);
                mViewHolder.subTitleView = (TextView)convertView.findViewById(R.id.videos_list_item_subtitle);
                mViewHolder.playNumView = (TextView)convertView.findViewById(R.id.videos_list_item_playnum);
                mViewHolder.videoTime = (TextView)convertView.findViewById(R.id.video_time);
                mViewHolder.videoScore = (TextView)convertView.findViewById(R.id.videos_list_item_score);
                mViewHolder.videoImageView = (LetvImageView)convertView.findViewById(R.id.detail_half_video_image);
                convertView.setTag(mViewHolder);
            } else {
                mViewHolder = (ViewChildHolderListView) convertView.getTag();                
                clearViewData(mViewHolder);
            }
            createVideosList(curVid, mViewHolder, mVideo, convertView);
        }
        return convertView;
    }

//    private void setGridViewHeight(GridView gridView, VideoListBean mCurVideoList) {
//        if (gridView == null || mCurVideoList == null) {
//            return;
//        }
//        int listSize = mCurVideoList.size();
//        ViewGroup.LayoutParams layoutParams = gridView.getLayoutParams();
//        if (layoutParams == null || listSize == 0) {
//           return;
//        }
//        int lineNum = listSize % mNumColumns != 0 ? listSize / mNumColumns + 1 : listSize / mNumColumns;
//        int itemHeight = UIsUtils.dipToPx(43);
//        int pading = UIsUtils.dipToPx(10);
//        int verticalSpacing = UIsUtils.dipToPx(10);
//        int height = getGridViewHeight(lineNum, itemHeight, pading, verticalSpacing);
//        layoutParams.height = height;
//    }

    /**
     * 换算gridview的高度
     * @param lineNum 行数
     * @param itemHeight 行高
     * @param padding
     * @param verticalSpacing 间隔
     * @return
     */
    private int getGridViewHeight(int lineNum, int itemHeight, int padding, int verticalSpacing) {
        if (lineNum == 0) {
            return 0;
        }
        int allVerticalSpacing = lineNum > 1 ? (lineNum - 1) * verticalSpacing : 0;
        return 2 * padding + lineNum * itemHeight + allVerticalSpacing;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        if(isList) {
            if (videosMap != null) {
                VideoListBean mVideoList = videosMap.get(groupPosition + 1);
                if (mVideoList != null) {
                    return mVideoList.size();
                }
            }
            return 0;
        } else {
            if (total == 0) {
                return 0;
            }
            if (pageSize == 0) {
                return 0;
            }
            return 1;
        }
    }

    public int getChildrenItemCount(int groupPosition) {
        if (videosMap != null) {
            VideoListBean mVideoList = videosMap.get(groupPosition + 1);
            if (mVideoList != null) {
                return mVideoList.size();
            }
        }
        return 0;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groupPosition;
    }

    @Override
    public int getGroupCount() {
        if (total == 0) {
            return 0;
        }
        if (pageSize == 0) {
            return 0;
        }
        return EpisodeUtils.calculateRows(total, pageSize);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public void setIsLandscape(boolean isLandscape) {
        this.isLandscape = isLandscape;
    }
    
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
            viewHolderGroup = new ViewHolderGroup();
            if (isLandscape) {
                convertView = layoutInflater.inflate(R.layout.letv_detail_full_expand_parent_selecter_playerlibs, parent, false);
                viewHolderGroup.titleView = (TextView) convertView.findViewById(R.id.title_text);
                viewHolderGroup.arrowView = (ImageView) convertView.findViewById(R.id.arrow);
                viewHolderGroup.progressBarView = (ProgressBar) convertView.findViewById(R.id.play_epsiode_progress);
            }
            else {
                convertView = layoutInflater.inflate(R.layout.letv_detail_half_expand_parent_selecter_playerlibs, parent, false);
                viewHolderGroup.titleView = (TextView) convertView.findViewById(R.id.title_text);
                viewHolderGroup.arrowView = (ImageView) convertView.findViewById(R.id.arrow);
                viewHolderGroup.progressBarView = (ProgressBar) convertView.findViewById(R.id.play_epsiode_progress);
            }
            convertView.setTag(viewHolderGroup);
        } else {
            viewHolderGroup = (ViewHolderGroup) convertView.getTag();
        }
        int star = pageSize * groupPosition + 1;
        int end = pageSize * (groupPosition + 1);
        if (end > total) {
            end = total;
        }
        groupRangceMap.put(groupPosition, new int[]{star, end});
        if(end==total&&null!=mAlbumNewPlayerLibs){
        	   viewHolderGroup.titleView.setText(star + "-" + end+mAlbumNewPlayerLibs.getMultiPageChannelTypeTitle()/*"(共"+episodes+"集)"*/);
		}else{
			   viewHolderGroup.titleView.setText(star + "-" + end);
		}
        if (isExpanded && getChildrenItemCount(groupPosition) == 0 && loadGroupPosition == groupPosition && loadProgressingFlag) {
            if (mViewHolder != null) {
                mViewHolder.top.setVisibility(View.GONE);
                mViewHolder.bottom.setVisibility(View.GONE);
            }
            viewHolderGroup.progressBarView.setVisibility(View.VISIBLE);
        } else {
            viewHolderGroup.progressBarView.setVisibility(View.GONE);
        }
        if (!isExpanded) {
            viewHolderGroup.arrowView.setBackgroundResource(R.drawable.letv_arrow_down_new);
            LogInfo.log("hong6", "setBackgroundResource(R.drawable.letv_arrow_down_new)");
        } else {
            viewHolderGroup.arrowView.setBackgroundResource(R.drawable.letv_arrow_up_new);
            LogInfo.log("hong6", "setBackgroundResource(R.drawable.letv_arrow_up_new)");
        }
        return convertView;	
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }

    public class ViewChildHolderGridView {
        public ExpandableHeightGridViewPlayerLibs expandChildGridView;
        public View top, bottom;
        public DetailVideosGridAdapterPlayerLibs expandChildGridViewAdapter;
    }
    public static class ViewChildHolderListView {
        public LetvImageView videoImageView;
        public TextView titleView;
        public TextView subTitleView;
        public TextView playNumView;
        public TextView localTextView;
        public TextView videoTime;
        public TextView videoScore;
    }

    /**
     *检测girdview是否滑动到底部，设置top和bottom可见
     */
    private AbsListView.OnScrollListener onGirdViewScrollListener  = new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (totalItemCount > 0 && firstVisibleItem + visibleItemCount >= totalItemCount) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        if (mViewHolder != null) {
                            mViewHolder.top.setVisibility(View.VISIBLE);
                            mViewHolder.bottom.setVisibility(View.VISIBLE);
                        }
                    }
                });
            }
        }
    };

    public void setOnItemClickListener(AdapterView.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public void setCurVid(long curVid) {
        this.curVid = curVid;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public void setVideosMap(HashMap<Integer, VideoListBean> videosMap) {
        this.videosMap = videosMap;
    }

    public void setCurrVideoPlayerLibs(VideoBean currVideoPlayerLibs) {
        this.currVideoPlayerLibs = currVideoPlayerLibs;
    }
    public void setBoolList(boolean isList) {
        this.isList = isList;
    }
    public long getAid() {
        return aid;
    }

    public void setAid(long aid) {
        this.aid = aid;
    }

    public void lock() {
        lock = true;
    }

    public void unLock() {
        lock = false;
    }
    /**
     * 清空上次使用时的图片资源和监听资源
     * */
    public void clearViewData(ViewChildHolderListView mViewHolder) {
        if (mViewHolder.videoImageView != null) {
            mViewHolder.videoImageView.setImageDrawable(null);
        }
        mViewHolder.localTextView.setText("");
        mViewHolder.titleView.setText("");
        mViewHolder.subTitleView.setText("");
        mViewHolder.playNumView.setText("");
        mViewHolder.videoTime.setText("");
        mViewHolder.videoScore.setText("");
    }
    public void configurePinnedHeader(View v, int position, int alpha) {
        int star = pageSize * position + 1;
        int end = pageSize * (position + 1);
        if (end > total) {
            end = total;
        }
        TextView header = (TextView) v;
        final String title = star + "-" + end;
        header.setText(title);
        if (alpha == 255) {
            header.setBackgroundColor(mPinnedHeaderBackgroundColor);
            header.setTextColor(mPinnedHeaderTextColor);
            header.setVisibility(View.VISIBLE);
        } else {
            header.setVisibility(View.GONE);
            header.setBackgroundColor(Color.argb(alpha,
                    Color.red(mPinnedHeaderBackgroundColor),
                    Color.green(mPinnedHeaderBackgroundColor),
                    Color.blue(mPinnedHeaderBackgroundColor)));
            header.setTextColor(Color.argb(alpha,
                    Color.red(mPinnedHeaderTextColor),
                    Color.green(mPinnedHeaderTextColor),
                    Color.blue(mPinnedHeaderTextColor)));
        }
    }
}
